#pragma once

#include "qamqpclient.h"
#include "qamqpexchange.h"
#include "qamqpqueue.h"
#include <QObject>
struct RabblitMQ 
{
    struct Connect 
    {
        QString hostName;
        int port;
        QString virHost;
        QString userName;
        QString userPassword;
    } connection;

    struct Exchange 
    {
        QString name;
        int type;
    } exchange;

    struct Queue 
    {
        QString name;
    } queue;

    QStringList bindingkeys;
    // QStringList routingkey;
};

class RabbitMQReceiver : public QObject {
    Q_OBJECT
public:
    explicit RabbitMQReceiver(QObject* parent = nullptr);
    ~RabbitMQReceiver();

    void setHost(QString host, int port, QString virHost = "/", QString userName = "guest", QString pw = "guest");
    void setExchange(QString name);
    void start(QString exchange, QString queueName, QStringList bindingkeys);
    void stop();
    void publish(QString routingkey, QString msg);

signals:
    void recv_msg(QString routingkey, QString msg);
public slots:
    void clientConnected();
    void exchangeDeclared();
    void queueDeclared();
    void queueBound();
    void messageReceived();
    void clientDisconnected();
    void on_error(QAMQP::Error error);

private:
    RabblitMQ m_info;
    QAmqpClient m_client;
    bool m_isStart = false;
    QAmqpExchange* m_exchange = nullptr;
};
